import Vue from 'vue';

export default {
    setToken(token, expireTime) {
        var expired = new Date().valueOf() + expireTime * 1000;

        Vue.http.headers.common['token'] = token;
        window.localStorage.setItem("MeebidAdminToken", token);
        window.localStorage.setItem("MeebidAdminTokenExpireTime", expired);
    },
    autoLogin() {
        var expired = window.localStorage.getItem("MeebidAdminTokenExpireTime");
        var token = window.localStorage.getItem("MeebidAdminToken");
        if (token == undefined || token == null || token == "") {
            return false;
        }
        if (expired < new Date().valueOf()) {
            return false;
        }

        Vue.http.headers.common['token'] = token;
        return true;
    },
    resetToken() {
        window.localStorage.setItem("MeebidAdminToken", "");
        window.localStorage.setItem("MeebidAdminTokenExpireTime", 0);
    }
}